package com.mallcloud.mall.mall.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mallcloud.mall.common.core.util.R;
import com.mallcloud.mall.common.core.util.ValidGroup;
import com.mallcloud.mall.common.excel.annotation.ResponseExcel;
import com.mallcloud.mall.mall.api.entity.MallFloorModel;
import com.mallcloud.mall.mall.service.MallFloorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "mall-楼层")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mall/floor")
public class MallFloorController {
	private final MallFloorService mallfloorService;

	@ApiOperation("分页")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('mall_floor_view')")
	public R<IPage<MallFloorModel>> page(Page page, MallFloorModel mallfloor) {
		return R.ok(mallfloorService.page(page, Wrappers.query(mallfloor)));
	}

	@ApiOperation("查询")
	@GetMapping("/{floorId}")
	@PreAuthorize("@pms.hasPermission('mall_floor_view')")
	public R<MallFloorModel> getById(@PathVariable("floorId") Long floorId) {
		return R.ok(mallfloorService.getById(floorId));
	}

	@ApiOperation("新增")
	@PostMapping("/save")
	@PreAuthorize("@pms.hasPermission('mall_floor_add')")
	public R<Boolean> save(@RequestBody MallFloorModel mallfloor) {
		return R.ok(mallfloorService.save(mallfloor));
	}

	@ApiOperation("修改")
	@PostMapping("/update")
	@PreAuthorize("@pms.hasPermission('mall_floor_edit')")
	public R<Boolean> updateById(@Validated({ValidGroup.Update.class }) @RequestBody MallFloorModel mallfloor) {
		return R.ok(mallfloorService.updateById(mallfloor));
	}

	@ApiOperation("删除")
	@DeleteMapping("/{floorid}")
	@PreAuthorize("@pms.hasPermission('mall_floor_del')")
	public R<Boolean> removeById(@PathVariable Long floorid) {
		return R.ok(mallfloorService.removeById(floorid));
	}

	@ApiOperation("导出")
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('mall_floor_export')")
	public List<MallFloorModel> export(MallFloorModel mallfloor) {
		return mallfloorService.list(Wrappers.query(mallfloor));
	}
}
